﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity.Migrations;
using KidChoreApp.DataModels;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;

namespace KidChoreApp.Data
{
    public class Seeder
    {
        public static void Seed(ApplicationDbContext db, bool seedKid = true, bool seedChore = true, bool seedKidChore = true, bool seedUsers = true)
        {
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //

            if (seedUsers)
            {
                List<ApplicationUser> users = new List<ApplicationUser>()
                {
                    new ApplicationUser(){ UserName="JohnDoe" },
                    new ApplicationUser(){ UserName="JaneDoe" },
                    new ApplicationUser(){ UserName="TimmyDoe" }
                };

                var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(db));
                roleManager.Create(new IdentityRole { Name = "Admin" });
              

                using (var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(db)))
                {
                    userManager.Create(users[0], "John123");
                    users[0] = userManager.FindByName(users[0].UserName);
                    userManager.Create(users[1], "Jane123");
                    userManager.Create(users[2], "Tim123");
                    db.SaveChanges();
                    userManager.AddToRole(users[0].Id, "Admin");
                }


            }

            if (seedKid)
            {
                db.Kids.AddOrUpdate(
                    p => p.Name,
                    new Kid { Name = "Dean", Grade = 12, Teacher = "Alex Miller" },
                    new Kid { Name = "Paul", Grade = 12, Teacher = "Alex Miller" },
                    new Kid { Name = "Taaha", Grade = 12, Teacher = "Alex Miller" },
                    new Kid { Name = "James", Grade = 12, Teacher = "Alex Miller" },
                    new Kid { Name = "Son", Grade = 12, Teacher = "Alex Miller" },
                    new Kid { Name = "Aaron", Grade = 12, Teacher = "Alex Miller" },
                    new Kid { Name = "Josh", Grade = 12, Teacher = "Alex Miller" },
                    new Kid { Name = "JohnDoe", Grade = 0, Teacher = "ALex Miller" }
                    );
                db.SaveChanges();
            }
            if (seedChore)
            {
                db.Chores.AddOrUpdate(
                    p => p.Name,
                    new Chore { Name = "Wash Board", Room = "A", IsDone = false, IsRecurring = false },
                    new Chore { Name = "Wash Floor", Room = "B", IsDone = false, IsRecurring = false },
                    new Chore { Name = "Wash Desk", Room = "C", IsDone = false, IsRecurring = false },
                    new Chore { Name = "Wash Dishes", Room = "D", IsDone = false, IsRecurring = false },
                    new Chore { Name = "Wash Clothes", Room = "E", IsDone = false, IsRecurring = false },
                    new Chore { Name = "Wash Computer", Room = "F", IsDone = false, IsRecurring = false },
                    new Chore { Name = "Lick Floor Clean", Room = "G", IsDone = false, IsRecurring = false },
                    new Chore { Name = "Make Mess", Room = "H", IsDone = false, IsRecurring = false },
                    new Chore { Name = "Defrag HardDrive", Room = "A", IsDone = false, IsRecurring = false },
                    new Chore { Name = "Talk", Room = "B", IsDone = false, IsRecurring = false },
                    new Chore { Name = "Walk", Room = "C", IsDone = false, IsRecurring = false },
                    new Chore { Name = "Watch Star Wars", Room = "D", IsDone = false, IsRecurring = false },
                    new Chore { Name = "Talk About Star Wars", Room = "E", IsDone = false, IsRecurring = false }
                    );
                db.SaveChanges();
            }
            if (seedKidChore)
            {
                db.KidChores.AddOrUpdate(
                    p => new { p.KidId, p.ChoreId },
                    new KidChore { KidId = 1, ChoreId = 1 },
                        new KidChore { KidId = 2, ChoreId = 1 },
                            new KidChore { KidId = 3, ChoreId = 1 },
                                new KidChore { KidId = 4, ChoreId = 1 },
                                    new KidChore { KidId = 5, ChoreId = 1 },
                                        new KidChore { KidId = 6, ChoreId = 1 },
                                            new KidChore { KidId = 7, ChoreId = 1 },
                                                new KidChore { KidId = 8, ChoreId = 1 },
                    new KidChore { KidId = 1, ChoreId = 2 },
                        new KidChore { KidId = 2, ChoreId = 2 },
                            new KidChore { KidId = 3, ChoreId = 2 },
                                new KidChore { KidId = 4, ChoreId = 2 },
                                    new KidChore { KidId = 5, ChoreId = 2 },
                                        new KidChore { KidId = 6, ChoreId = 2 },
                                            new KidChore { KidId = 7, ChoreId = 2 },
                    new KidChore { KidId = 1, ChoreId = 3 },
                        new KidChore { KidId = 2, ChoreId = 3 },
                            new KidChore { KidId = 3, ChoreId = 3 },
                                new KidChore { KidId = 4, ChoreId = 3 },
                                    new KidChore { KidId = 5, ChoreId = 3 },
                                        new KidChore { KidId = 6, ChoreId = 3 },
                    new KidChore { KidId = 1, ChoreId = 4 },
                        new KidChore { KidId = 2, ChoreId = 4 },
                            new KidChore { KidId = 3, ChoreId = 4 },
                                new KidChore { KidId = 4, ChoreId = 4 },
                                    new KidChore { KidId = 5, ChoreId = 4 },
                    new KidChore { KidId = 1, ChoreId = 5 },
                        new KidChore { KidId = 2, ChoreId = 5 },
                            new KidChore { KidId = 3, ChoreId = 5 },
                                new KidChore { KidId = 4, ChoreId = 5 },
                    new KidChore { KidId = 1, ChoreId = 6 },
                        new KidChore { KidId = 2, ChoreId = 6 },
                            new KidChore { KidId = 3, ChoreId = 6 },
                    new KidChore { KidId = 1, ChoreId = 7 },
                        new KidChore { KidId = 2, ChoreId = 7 },
                                                new KidChore { KidId = 1, ChoreId = 8 },
                     new KidChore { KidId = 1, ChoreId = 13 },
                        new KidChore { KidId = 2, ChoreId = 13 },
                            new KidChore { KidId = 3, ChoreId = 13 },
                                new KidChore { KidId = 4, ChoreId = 13 },
                                    new KidChore { KidId = 5, ChoreId = 13 },
                    new KidChore { KidId = 1, ChoreId = 12 },
                        new KidChore { KidId = 2, ChoreId = 12 },
                            new KidChore { KidId = 3, ChoreId = 12 },
                                new KidChore { KidId = 4, ChoreId = 12 },
                    new KidChore { KidId = 1, ChoreId = 11 },
                        new KidChore { KidId = 2, ChoreId = 11 },
                            new KidChore { KidId = 3, ChoreId = 11 },
                    new KidChore { KidId = 1, ChoreId = 10 },
                        new KidChore { KidId = 2, ChoreId = 10 },
                                                new KidChore { KidId = 1, ChoreId = 9 }
                    );
                db.SaveChanges();



            }
        }
    }
}
